package rpc

import (
	"chat/lib/chat"
	"chat/rpc/pb"
	"encoding/json"
	"log"
)

type server struct {
}

func (s *server) Notify(cli pb.IPCService_NotifyServer) error {
	for {
		if frame, err := cli.Recv(); err == nil {
			switch frame.Code {
			case pb.IPC_chat:
				var msg = &chat.Message{}
				err := json.Unmarshal(frame.Data, msg)
				if err != nil {
					log.Println(err)
				}
				chat.Mgr.Receive(msg)
			}
		} else {
			log.Println("break, err :", err)
			break
		}
	}
	return nil
}
